﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
using Quickuse.Logging.EsLogger;
using System;
using System.Collections.Generic;
using System.Text;

namespace Quickuse.Logging.EsLogger
{
    /// <summary>
    /// 
    /// </summary>
    public static class EsLoggerExtensions
    {
        /// <summary>
        /// Add Es
        /// </summary>
        /// <param name="builder">builder</param>
        /// <returns></returns>
        public static ILoggingBuilder AddEs(this ILoggingBuilder builder)
        {
            builder.Services.TryAddSingleton<ILoggingConfiguration, LoggingConfiguration>();
            builder.Services.TryAddSingleton<IEsLoggerSettings, EsLoggerSettings>();
            builder.Services.TryAddSingleton<EsLoggerProcessor, EsLoggerProcessor>();
            builder.Services.AddSingleton<ILoggerProvider, EsLoggerProvider>();

            return builder;
        }

        /// <summary>
        /// AddEs
        /// </summary>
        /// <param name="builder">builder</param>
        /// <param name="configuration">configuration</param>
        /// <returns></returns>
        public static ILoggingBuilder AddEs(this ILoggingBuilder builder, IConfiguration configuration)
        {
            builder.Services.TryAddSingleton<ILoggingConfiguration, LoggingConfiguration>();
            builder.Services.TryAddSingleton<IConfiguration>(configuration);
            builder.Services.TryAddSingleton<IEsLoggerSettings, EsLoggerSettings>();
            builder.Services.TryAddSingleton<EsLoggerProcessor, EsLoggerProcessor>();
            builder.Services.AddSingleton<ILoggerProvider, EsLoggerProvider>();

            return builder;
        }
    }
}
